home *** CD-ROM | disk | FTP | other *** search
/ MPEG Toolkit / MPEG Toolkit.iso / dos / mpegstat / video.h < prev   
Encoding:
C/C++ Source or Header  |  1997-01-01  |  11.6 KB  |  291 lines

  1. /* MPEGSTAT - analyzing tool for MPEG-I video streams
  2.  * 
  3.  * Technical University of Berlin, Germany, Dept. of Computer Science
  4.  * Tom Pfeifer - Multimedia systems project - pfeifer@fokus.gmd.de
  5.  *
  6.  * Jens Brettin, Harald Masche, Alexander Schulze, Dirk Schubert
  7.  *
  8.  * This program uses parts of the source code of the Berkeley MPEG player
  9.  *
  10.  * ---------------------------
  11.  *
  12.  * Copyright (c) 1993 Technical University of Berlin, Germany
  13.  *
  14.  * for the parts of the Berkeley player used:
  15.  *
  16.  * Copyright (c) 1992 The Regents of the University of California.
  17.  * All rights reserved.
  18.  *
  19.  * ---------------------------
  20.  *
  21.  * Permission to use, copy, modify, and distribute this software and its
  22.  * documentation for any purpose, without fee, and without written agreement is
  23.  * hereby granted, provided that the above copyright notices and the following
  24.  * two paragraphs appear in all copies of this software.
  25.  * 
  26.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA 
  27.  * or the Technical University of Berlin BE LIABLE TO ANY PARTY FOR
  28.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  29.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  30.  * CALIFORNIA or the Technical University of Berlin HAS BEEN ADVISED OF THE 
  31.  * POSSIBILITY OF SUCH DAMAGE.
  32.  * 
  33.  * THE UNIVERSITY OF CALIFORNIA and the Technical University of Berlin 
  34.  * SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
  35.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  36.  * PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE 
  37.  * UNIVERSITY OF CALIFORNIA and the Technical University of Berlin HAVE NO 
  38.  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, 
  39.  * OR MODIFICATIONS.
  40.  */
  41. #include <stdio.h>
  42. #include <setjmp.h>
  43.  
  44. /* X11/xmd.h correctly defines INT32, etc */
  45. #ifndef XMD_H
  46. typedef int INT32;
  47. typedef short INT16;
  48. typedef char INT8;
  49. #endif
  50. typedef unsigned int UINT32;
  51. typedef unsigned short UINT16;
  52. typedef unsigned char UINT8;
  53.  
  54. /* Define Parsing error codes. */
  55.  
  56. #define SKIP_PICTURE -10
  57. #define SKIP_TO_START_CODE -1
  58. #define PARSE_OK 1
  59.  
  60. /* Define BOOLEAN, TRUE, and FALSE. */
  61.  
  62. #define BOOLEAN int
  63. #define TRUE 1
  64. #define FALSE 0
  65.  
  66. /* Set ring buffer size. */
  67.  
  68. #define RING_BUF_SIZE 5
  69.  
  70. /* Macros for picture code type. */
  71.  
  72. #define I_TYPE 1
  73. #define P_TYPE 2
  74. #define B_TYPE 3
  75.  
  76. /* Start codes. */
  77.  
  78. #define SEQ_END_CODE 0x000001b7
  79. #define SEQ_START_CODE 0x000001b3
  80. #define GOP_START_CODE 0x000001b8
  81. #define PICTURE_START_CODE 0x00000100
  82. #define SLICE_MIN_START_CODE 0x00000101
  83. #define SLICE_MAX_START_CODE 0x000001af
  84. #define EXT_START_CODE 0x000001b5
  85. #define USER_START_CODE 0x000001b2
  86.  
  87. /* Number of macroblocks to process in one call to mpegVidRsrc. */
  88.  
  89. #define MB_QUANTUM 100
  90.  
  91. /* Macros used with macroblock address decoding. */
  92.  
  93. #define MB_STUFFING 34
  94. #define MB_ESCAPE 35
  95.  
  96. /* Lock flags for pict images. */
  97.  
  98. #define DISPLAY_LOCK 0x01
  99. #define PAST_LOCK 0x02
  100. #define FUTURE_LOCK 0x04
  101.  
  102. #define HYBRID_DITHER 0
  103. #define HYBRID2_DITHER 1
  104. #define FS4_DITHER 2
  105. #define FS2_DITHER 3
  106. #define FS2FAST_DITHER 4
  107. #define Twox2_DITHER 5
  108. #define GRAY_DITHER 6
  109. #define FULL_COLOR_DITHER 7
  110. #define NO_DITHER 8
  111. #define ORDERED_DITHER 9
  112. #define MONO_DITHER 10
  113. #define MONO_THRESHOLD 11
  114. #define ORDERED2_DITHER 12
  115. #define MBORDERED_DITHER 13
  116.  
  117. /* External declaration of row,col to zig zag conversion matrix. */
  118.  
  119. extern int scan[][8];
  120.  
  121. /* Temporary definition of time stamp structure. */
  122.  
  123. typedef int TimeStamp;
  124.  
  125. /* Structure with reconstructed pixel values. */
  126.  
  127. typedef struct pict_image {
  128.   unsigned char *luminance;              /* Luminance plane.   */
  129.   unsigned char *Cr;                     /* Cr plane.          */
  130.   unsigned char *Cb;                     /* Cb plane.          */
  131.   unsigned char *display;                /* Display plane.     */
  132.   int locked;                            /* Lock flag.         */
  133.   TimeStamp show_time;                   /* Presentation time. */
  134.  
  135. #ifdef SH_MEM
  136.   XShmSegmentInfo shminfo;               /* Segment info.  */
  137.   XImage *ximage;                        /* Ximage struct. */
  138. #endif
  139.  
  140. } PictImage;
  141.  
  142. /* Group of pictures structure. */
  143.  
  144. typedef struct GoP {
  145.   BOOLEAN drop_flag;                     /* Flag indicating dropped frame. */
  146.   unsigned int tc_hours;                 /* Hour component of time code.   */
  147.   unsigned int tc_minutes;               /* Minute component of time code. */
  148.   unsigned int tc_seconds;               /* Second component of time code. */
  149.   unsigned int tc_pictures;              /* Picture counter of time code.  */
  150.   BOOLEAN closed_gop;                    /* Indicates no pred. vectors to
  151.                         previous group of pictures.    */
  152.   BOOLEAN broken_link;                   /* B frame unable to be decoded.  */
  153.   char *ext_data;                        /* Extension data.                */
  154.   char *user_data;                       /* User data.                     */
  155. } GoP;
  156.  
  157. /* Picture structure. */
  158.  
  159. typedef struct pict {
  160.   unsigned int temp_ref;                 /* Temporal reference.             */
  161.   unsigned int code_type;                /* Frame type: P, B, I             */
  162.   unsigned int vbv_delay;                /* Buffer delay.                   */
  163.   BOOLEAN full_pel_forw_vector;          /* Forw. vectors specified in full
  164.                         pixel values flag.              */
  165.   unsigned int forw_r_size;              /* Used for vector decoding.       */
  166.   unsigned int forw_f;                   /* Used for vector decoding.       */
  167.   BOOLEAN full_pel_back_vector;          /* Back vectors specified in full 
  168.                         pixel values flag.              */
  169.   unsigned int back_r_size;              /* Used in decoding.               */
  170.   unsigned int back_f;                   /* Used in decoding.               */
  171.   char *extra_info;                      /* Extra bit picture info.         */
  172.   char *ext_data;                        /* Extension data.                 */
  173.   char *user_data;                       /* User data.                      */
  174. } Pict;
  175.  
  176. /* Slice structure. */
  177.  
  178. typedef struct slice {
  179.   unsigned int vert_pos;                 /* Vertical position of slice. */
  180.   unsigned int quant_scale;              /* Quantization scale.         */
  181.   char *extra_info;                      /* Extra bit slice info.       */
  182. } Slice;
  183.  
  184. /* Macroblock structure. */
  185.  
  186. typedef struct macroblock {
  187.   int mb_address;                        /* Macroblock address.              */
  188.   int past_mb_addr;                      /* Previous mblock address.         */
  189.   int motion_h_forw_code;                /* Forw. horiz. motion vector code. */
  190.   unsigned int motion_h_forw_r;          /* Used in decoding vectors.        */
  191.   int motion_v_forw_code;                /* Forw. vert. motion vector code.  */
  192.   unsigned int motion_v_forw_r;          /* Used in decdoinge vectors.       */
  193.   int motion_h_back_code;                /* Back horiz. motion vector code.  */
  194.   unsigned int motion_h_back_r;          /* Used in decoding vectors.        */
  195.   int motion_v_back_code;                /* Back vert. motion vector code.   */
  196.   unsigned int motion_v_back_r;          /* Used in decoding vectors.        */
  197.   unsigned int cbp;                      /* Coded block pattern.             */
  198.   BOOLEAN mb_intra;                      /* Intracoded mblock flag.          */
  199.   BOOLEAN bpict_past_forw;               /* Past B frame forw. vector flag.  */
  200.   BOOLEAN bpict_past_back;               /* Past B frame back vector flag.   */
  201.   int past_intra_addr;                   /* Addr of last intracoded mblock.  */
  202.   int recon_right_for_prev;              /* Past right forw. vector.         */
  203.   int recon_down_for_prev;               /* Past down forw. vector.          */
  204.   int recon_right_back_prev;             /* Past right back vector.          */
  205.   int recon_down_back_prev;              /* Past down back vector.           */
  206. } Macroblock;
  207.  
  208. /* Block structure. */
  209.  
  210. typedef struct block {
  211.   short int dct_recon[8][8];             /* Reconstructed dct coeff matrix. */
  212.   short int dct_dc_y_past;               /* Past lum. dc dct coefficient.   */
  213.   short int dct_dc_cr_past;              /* Past cr dc dct coefficient.     */
  214.   short int dct_dc_cb_past;              /* Past cb dc dct coefficient.     */
  215. } Block;
  216.  
  217. /* Video stream structure. */
  218.  
  219. typedef struct vid_stream {
  220.   unsigned int h_size;                         /* Horiz. size in pixels.     */
  221.   unsigned int v_size;                         /* Vert. size in pixels.      */
  222.   unsigned int mb_height;                      /* Vert. size in mblocks.     */
  223.   unsigned int mb_width;                       /* Horiz. size in mblocks.    */
  224.   unsigned char aspect_ratio;                  /* Code for aspect ratio.     */
  225.   unsigned char picture_rate;                  /* Code for picture rate.     */
  226.   unsigned int bit_rate;                       /* Bit rate.                  */
  227.   unsigned int vbv_buffer_size;                /* Minimum buffer size.       */
  228.   BOOLEAN const_param_flag;                    /* Contrained parameter flag. */
  229.   unsigned char intra_quant_matrix[8][8];      /* Quantization matrix for
  230.                           intracoded frames.         */
  231.   unsigned char non_intra_quant_matrix[8][8];  /* Quanitization matrix for 
  232.                           non intracoded frames.     */
  233.   char *ext_data;                              /* Extension data.            */
  234.   char *user_data;                             /* User data.                 */
  235.   GoP group;                                   /* Current group of pict.     */
  236.   Pict picture;                                /* Current picture.           */
  237.   Slice slice;                                 /* Current slice.             */
  238.   Macroblock mblock;                           /* Current macroblock.        */
  239.   Block block;                                 /* Current block.             */
  240.   int state;                                   /* State of decoding.         */
  241.   int bit_offset;                              /* Bit offset in stream.      */
  242.   unsigned int *buffer;                        /* Pointer to next byte in
  243.                           buffer.                    */
  244.   int buf_length;                              /* Length of remaining buffer.*/
  245.   unsigned int *buf_start;                     /* Pointer to buffer start.   */
  246.   int max_buf_length;                          /* Max lenght of buffer.      */
  247.   PictImage *past;                             /* Past predictive frame.     */
  248.   PictImage *future;                           /* Future predictive frame.   */
  249.   PictImage *current;                          /* Current frame.             */
  250.   PictImage *ring[RING_BUF_SIZE];              /* Ring buffer of frames.     */
  251. } VidStream;   
  252.  
  253. /* Declaration of global pointer to current video stream. */
  254.  
  255. extern VidStream *curVidStream;
  256.  
  257. /* Shared memory flag. */
  258. extern int shmemFlag;
  259.  
  260. /* Quiet mode flag. */
  261. extern int quietFlag;
  262.  
  263. /* Dither flags external declaration. */
  264. extern char *ditherFlags;
  265.  
  266. /* Definition of Contant integer scale factor. */
  267.  
  268. #define CONST_BITS 13
  269.  
  270. /* Misc DCT definitions */
  271. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  272. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  273.  
  274. #define GLOBAL            /* a function referenced thru EXTERNs */
  275.   
  276. typedef short DCTELEM;
  277. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  278.  
  279.  
  280. extern double realTimeStart;
  281. extern int totNumFrames;
  282. extern int loopFlag;
  283. extern int noDisplayFlag;
  284. extern jmp_buf env;
  285.  
  286. extern unsigned int bitCount;
  287. extern int showEachFlag;
  288. extern unsigned int cacheHit[8][8];
  289. extern unsigned int cacheMiss[8][8];
  290.  
  291.